// import '@pnp/common';
// import '@pnp/odata';
// import '@pnp/logging';
// import { sp } from '@pnp/sp';
// import '@pnp/sp/webs';
// import '@pnp/sp/lists';
// import '@pnp/sp/items';
// import '@pnp/sp/search';
// import '@pnp/sp/attachments';
// import '@pnp/sp/files';
// import '@pnp/sp/folders';
// import '@pnp/sp/site-users/web';
// import { ISearchQuery, SearchResults, SearchQueryBuilder } from '@pnp/sp/search';
// import { ICamlQuery } from '@pnp/sp/lists';
// import { Guid } from '@microsoft/sp-core-library';
// import { ISiteUserInfo } from '@pnp/sp/site-users/types';
// import { split } from 'lodash';
// import Api from './api';
// import {
//   taskGuid, //我的任务
//   ApproverListGUID, //审批链路
//   writListGUID,
//   DepartmentListGUID,
//   EmailGroupsListGUID, //邮件组
//   departmentsListGUID,
//   DocTypeListGUID, //文档类型列表GUID
//   NewDocListGUID, //新建文档申请列表GUID
//   GXListGUID, //工序列表GUID
//   MyApplyListGUID, //我的申请列表GUID
//   NewDocApproveHistoryListGUID,
//   changeListGUID, //变更文档申请GUID
//   changeApproveListGUID, //变更文档申请审批记录GUID
//   AbandonListGUID, //废弃文档申请GUID
//   AbandonApproveListGUID, //废弃文档申请审批记录GUID
// } from './ListGuid';

import { Guid } from "@microsoft/sp-core-library"

// //我的任务
// const MyTaskListGUID = taskGuid;

// export default class CommonHelper {
//   /**
//    * 新建文档申请 批量审批
//    *
//    *  @param taskIds 需要审批的任务id数组
//    *  @param status 需要审批的状态 默认为同意状态,若拒绝或退回,请提供"退回"  "拒绝" 值
//    *  @param comments 审批意见 默认为空字符串,若拒绝或退回,必须提供此参数
//    *  @returns 无
//    */
//   public static async _batchNewDocApprove(taskIds: number[], status: string = '同意', comments: string = ''): Promise<boolean> {
//     if (taskIds && taskIds.length > 0) {
//       for (let index = 0; index < taskIds.length; index++) {
//         let taskid = taskIds[index];
//         await this._newDocApproveItem(taskid, status, comments);
//         
//       }
//     }
//     
//     return true;
//   }

//   /**
//    * 变更文档申请 批量审批
//    *
//    *  @param taskIds 需要审批的任务id数组
//    *  @param status 需要审批的状态 默认为同意状态
//    *  @returns 无
//    */
//    public static async _batchUpdateFileApprove(taskIds: number[], status: string = '同意', comments = '') {
//     if (taskIds && taskIds.length > 0) {
//       for (let index = 0; index < taskIds.length; index++) {
//         let taskid = taskIds[index];
//         await this._updateDocApproveItem(taskid, status, comments);
//       }
//     }
//     
//     return true;
//   }

//   /**
//    * 废弃文档申请 批量审批
//    *
//    *  @param taskIds 需要审批的任务id数组
//    *  @param status 需要审批的状态 默认为同意状态
//    *  @returns 无
//    */
//   public static async _batchAbandonApprove(taskIds: number[], status: string = '同意', comments = '') {
//     if (taskIds && taskIds.length > 0) {
//       for (let index = 0; index < taskIds.length; index++) {
//         let taskid = taskIds[index];
//         await this._abandonDocApproveItem(taskid, status, comments);
//       }
//     }
//     
//     return true;
//   }

//   /**
//    * 新建文档申请 单个审批
//    *
//    *  @param taskIds 需要审批的任务id数组
//    *  @param status 需要审批的状态 默认为同意状态,若拒绝或退回,请提供"退回"  "拒绝" 值
//    *  @param comments 审批意见 默认为空字符串,若拒绝或退回,必须提供此参数
//    *  @returns 无
//    */
//   public static async _newDocApproveItem(taskId: number, status: string = '同意', comments = '') {
//     //我的任务 item
//     let taskItem = await Api.GetListItemById({ ListGUID: MyTaskListGUID, ItemId: taskId });
//     if (taskItem) {
//       //新建文档申请的ID
//       let newDocApplyId = taskItem.NewDocApplyID;

//       //新建文档申请 item
//       let newDocApplyItem = await Api.GetListItemById({ ListGUID: NewDocListGUID, ItemId: newDocApplyId });
//       if (newDocApplyItem) {
//         let {
//           ApproverItemID, //审批链路Id
//           AuthorUser,
//           Title,
//           AuthorDepartment,
//           DocDepartment,
//           DocProcedure,
//           DocSection,
//           DocType,
//           OPLSNumber,
//           DocName,
//           DocDescription,
//           AuthorId,
//           DocVersionNumber
//         } = newDocApplyItem;

//         //获取审批链路中各审批人
//         let approvers = await Api.GetListItemById({ ListGUID: ApproverListGUID, ItemId: ApproverItemID });
//         if (approvers) {
//           let { SpareAId, SpareBId, SpareCId, SpareDId, SpareEId, SpareFId, FirstApproverId, SecondApproverId } = approvers;
//           let ApproverList = {
//             SpareAId,
//             SpareBId,
//             SpareCId,
//             SpareDId,
//             SpareEId,
//             SpareFId,
//             FirstApproverId,
//             SecondApproverId,
//             AuthorId
//           };

//           //取出来需要展示的字段由于与审批记录列表的列高度重合，所以此处即用此对象展示数据，也用此对象存储数据
//           let Approver = '';
//           //获取当前用户
//           var u = await Api._getcurrentUser();
//           if (u) {
//             Approver = u.Title; //TODO:log(u)测试 用户名真正属性
//             
//           }
//           let NewDocApproveHistoryList = {
//             AuthorUser,
//             Title,
//             AuthorDepartment,
//             DocDepartment,
//             DocProcedure,
//             DocSection,
//             DocType,
//             OPLSNumber,
//             DocName,
//             DocDescription,
//             Approver,
//             ApproveAction: status, //审批操作
//             Approvalcomments: comments, //审批意见
//             MyTaskID: taskId,
//             CurrentApproverId: 0, //当前审批人
//             Continue: '', //是否继续审批
//             DocVersionNumber
//           };

//           //当前审批节点
//           let currentApproveNode = taskItem.ApprovalNode;
//           //当前审批人
//           let currentApproverId = taskItem.OData__x5ba1__x6279__x4eba_Id;

//           let nextApproverId = 0;
//           let nextApproveApproveNode = '';
//           let continueApprove = '是'; //是否继续审批
//           if (currentApproveNode == '申请人修改') {
//             //说明批量审批操作有误，不能将"申请人修改"状态的单子批量进行审批
//             return;
//           }
//           if (status == '同意') {
//             let { SpareAId, SpareBId, SpareCId, SpareDId, SpareEId, SpareFId, FirstApproverId, SecondApproverId } = ApproverList;

//             if (currentApproveNode == '部门文书审批') {
//               //判断是否
//               if (SpareAId != '' && SpareAId != null) {
//                 nextApproverId = SpareAId;
//                 nextApproveApproveNode = '审批人1审批';
//               } else if (SpareBId != '' && SpareBId != null) {
//                 nextApproverId = SpareBId;
//                 nextApproveApproveNode = '审批人2审批';
//               } else if (FirstApproverId != '' && FirstApproverId != null) {
//                 nextApproverId = FirstApproverId;
//                 nextApproveApproveNode = '一级审批';
//               } else if (SpareCId != '' && SpareCId != null) {
//                 nextApproverId = SpareCId;
//                 nextApproveApproveNode = '审批人3审批';
//               } else if (SpareDId != '' && SpareDId != null) {
//                 nextApproverId = SpareDId;
//                 nextApproveApproveNode = '审批人4审批';
//               } else if (SecondApproverId != '' && SecondApproverId != null) {
//                 nextApproverId = SecondApproverId;
//                 nextApproveApproveNode = '二级审批';
//               } else if (SpareEId != '' && SpareEId != null) {
//                 nextApproverId = SpareEId;
//                 nextApproveApproveNode = '审批人5审批';
//               } else if (SpareFId != '' && SpareFId != null) {
//                 nextApproverId = SpareFId;
//                 nextApproveApproveNode = '审批人6审批';
//               } else {
//                 nextApproveApproveNode = '审批通过';
//                 continueApprove = '否';
//               }
//             } else if (currentApproveNode == '审批人1审批') {
//               if (SpareBId != '' && SpareBId != null) {
//                 nextApproverId = SpareBId;
//                 nextApproveApproveNode = '审批人2审批';
//               } else if (FirstApproverId != '' && FirstApproverId != null) {
//                 nextApproverId = FirstApproverId;
//                 nextApproveApproveNode = '一级审批';
//               } else if (SpareCId != '' && SpareCId != null) {
//                 nextApproverId = SpareCId;
//                 nextApproveApproveNode = '审批人3审批';
//               } else if (SpareDId != '' && SpareDId != null) {
//                 nextApproverId = SpareDId;
//                 nextApproveApproveNode = '审批人4审批';
//               } else if (SecondApproverId != '' && SecondApproverId != null) {
//                 nextApproverId = SecondApproverId;
//                 nextApproveApproveNode = '二级审批';
//               } else if (SpareEId != '' && SpareEId != null) {
//                 nextApproverId = SpareEId;
//                 nextApproveApproveNode = '审批人5审批';
//               } else if (SpareFId != '' && SpareFId != null) {
//                 nextApproverId = SpareFId;
//                 nextApproveApproveNode = '审批人6审批';
//               } else {
//                 nextApproveApproveNode = '审批通过';
//                 continueApprove = '否';
//               }
//             } else if (currentApproveNode == '审批人2审批') {
//               if (FirstApproverId != '' && FirstApproverId != null) {
//                 nextApproverId = FirstApproverId;
//                 nextApproveApproveNode = '一级审批';
//               } else if (SpareCId != '' && SpareCId != null) {
//                 nextApproverId = SpareCId;
//                 nextApproveApproveNode = '审批人3审批';
//               } else if (SpareDId != '' && SpareDId != null) {
//                 nextApproverId = SpareDId;
//                 nextApproveApproveNode = '审批人4审批';
//               } else if (SecondApproverId != '' && SecondApproverId != null) {
//                 nextApproverId = SecondApproverId;
//                 nextApproveApproveNode = '二级审批';
//               } else if (SpareEId != '' && SpareEId != null) {
//                 nextApproverId = SpareEId;
//                 nextApproveApproveNode = '审批人5审批';
//               } else if (SpareFId != '' && SpareFId != null) {
//                 nextApproverId = SpareFId;
//                 nextApproveApproveNode = '审批人6审批';
//               } else {
//                 nextApproveApproveNode = '审批通过';
//                 continueApprove = '否';
//               }
//             } else if (currentApproveNode == '一级审批') {
//               if (SpareCId != '' && SpareCId != null) {
//                 nextApproverId = SpareCId;
//                 nextApproveApproveNode = '审批人3审批';
//               } else if (SpareDId != '' && SpareDId != null) {
//                 nextApproverId = SpareDId;
//                 nextApproveApproveNode = '审批人4审批';
//               } else if (SecondApproverId != '' && SecondApproverId != null) {
//                 nextApproverId = SecondApproverId;
//                 nextApproveApproveNode = '二级审批';
//               } else if (SpareEId != '' && SpareEId != null) {
//                 nextApproverId = SpareEId;
//                 nextApproveApproveNode = '审批人5审批';
//               } else if (SpareFId != '' && SpareFId != null) {
//                 nextApproverId = SpareFId;
//                 nextApproveApproveNode = '审批人6审批';
//               } else {
//                 nextApproveApproveNode = '审批通过';
//                 continueApprove = '否';
//               }
//             } else if (currentApproveNode == '审批人3审批') {
//               if (SpareDId != '' && SpareDId != null) {
//                 nextApproverId = SpareDId;
//                 nextApproveApproveNode = '审批人4审批';
//               } else if (SecondApproverId != '' && SecondApproverId != null) {
//                 nextApproverId = SecondApproverId;
//                 nextApproveApproveNode = '二级审批';
//               } else if (SpareEId != '' && SpareEId != null) {
//                 nextApproverId = SpareEId;
//                 nextApproveApproveNode = '审批人5审批';
//               } else if (SpareFId != '' && SpareFId != null) {
//                 nextApproverId = SpareFId;
//                 nextApproveApproveNode = '审批人6审批';
//               } else {
//                 nextApproveApproveNode = '审批通过';
//                 continueApprove = '否';
//               }
//             } else if (currentApproveNode == '审批人4审批') {
//               if (SecondApproverId != '' && SecondApproverId != null) {
//                 nextApproverId = SecondApproverId;
//                 nextApproveApproveNode = '二级审批';
//               } else if (SpareEId != '' && SpareEId != null) {
//                 nextApproverId = SpareEId;
//                 nextApproveApproveNode = '审批人5审批';
//               } else if (SpareFId != '' && SpareFId != null) {
//                 nextApproverId = SpareFId;
//                 nextApproveApproveNode = '审批人6审批';
//               } else {
//                 nextApproveApproveNode = '审批通过';
//                 continueApprove = '否';
//               }
//             } else if (currentApproveNode == '二级审批') {
//               if (SpareEId != '' && SpareEId != null) {
//                 nextApproverId = SpareEId;
//                 nextApproveApproveNode = '审批人5审批';
//               } else if (SpareFId != '' && SpareFId != null) {
//                 nextApproverId = SpareFId;
//                 nextApproveApproveNode = '审批人6审批';
//               } else {
//                 nextApproveApproveNode = '审批通过';
//                 continueApprove = '否';
//               }
//             } else if (currentApproveNode == '审批人5审批') {
//               if (SpareFId != '' && SpareFId != null) {
//                 nextApproverId = SpareFId;
//                 nextApproveApproveNode = '审批人6审批';
//               } else {
//                 nextApproveApproveNode = '审批通过';
//                 continueApprove = '否';
//               }
//             } else if (currentApproveNode == '审批人6审批') {
//               nextApproveApproveNode = '审批通过';
//               continueApprove = '否';
//             }
//           } else if (status == '退回') {
//             nextApproveApproveNode = '申请人修改';
//             let { AuthorId } = ApproverList; //申请人修改时，需要将审批人员修改为申请人
//             nextApproverId = AuthorId;
//             continueApprove = '否';
//           } else {
//             //拒绝
//             nextApproveApproveNode = '审批拒绝';
//             continueApprove = '否';
//           }

//           //此次待更新的任务条目
//           let needUpdateTaskItem = {
//             OData__x5ba1__x6279__x4eba_Id: 0, //审批人的Id
//             ApprovalNode: '' //审批节点
//           };

//           needUpdateTaskItem.ApprovalNode = nextApproveApproveNode;
//           if (nextApproverId != 0) {
//             needUpdateTaskItem.OData__x5ba1__x6279__x4eba_Id = nextApproverId;
//           }

//           NewDocApproveHistoryList.Continue = continueApprove; //是否需要继续审批
//           NewDocApproveHistoryList.CurrentApproverId = currentApproverId; //当前审批人

//           //更新我的任务
//           let resultMyTask = await Api.UpdateItemByListGUID({ ListGUID: MyTaskListGUID, ItemId: taskId, Obj: needUpdateTaskItem });
//           //存储新建文档审批记录
//           let resultNewDocApproveHistory = await Api.AddItemByListGUID({
//             ListGUID: NewDocApproveHistoryListGUID,
//             Obj: NewDocApproveHistoryList
//           });
//           if (resultMyTask && resultNewDocApproveHistory) {
//             
//           }
//           
//         }
//       }
//     }
//   }

//   /**
//    * 变更文档申请审批
//    * @param taskId 我的任务id
//    * @param status 审批操作
//    * @param comments 审批意见，退回或拒绝必填
//    */
/**
 * name
 */

// public getColumnsByGUID(GUID g) {
//     var 
//     if(g==SiteAppSetting.AA) {

//         return   "circulation_department","advance_notificate_time","duration_of_contract","decision_flag","board_meeting","operation_meeting","mediate_or_single_decision","discuss_depart","reason_without_ddq","ddq_flag","decision_content_3","decision_content_2","expect_decide_date","secrecy","sinsei_code","sosiki_nm","apply_user_nm","decision_std","sign_contract","for_up_affairs","contract_confirm","company_name","apply_date","update_time","filename","company_code","company_name","contract_no""
//     }ELSE if(g==SiteAppSetting.BB) {

//         return   "SSSSSWEWEWEWE"
//     }
    
// }

//   public static async _updateDocApproveItem(taskId: number, status: string = '同意', comments = ''){
//     // 查询我的任务item
//     var task_params = {
//       ListGUID: taskGuid,//我的任务guid
//       ItemId: taskId,
//     }
//     var TaskItem = await Api.GetListItemById(task_params);
//     

//     if(TaskItem.ApprovalNode != '申请人修改'){
//       //修改状态为1, 流程执行中
//       var editTask_params = {
//         Guid: taskGuid,   //我的任务guid
//         ItemId: taskId,
//         Obj: {
//           "Status": 1
//         },
//       }
//       var updatetask = await Api._updateData(editTask_params);// 修改我的任务状态为1
//       
    
//       let Apply_Edit = {
//         Guid: MyApplyListGUID,   //我的申请guid
//         ItemId: TaskItem.MyApplyID,
//         Obj: {
//           "WFStatus": '流程执行中'
//         },
//       }
//       await Api._updateData(Apply_Edit);// 修改我的申请状态为 '流程执行中'

//       // 查询变更文档申请item
//       var updateItem_params = {
//         ListGUID: changeListGUID,//变更文档申请guid
//         ItemId: TaskItem.NewDocApplyID,
//       }
//       var updateItem_Item = await Api.GetListItemById(updateItem_params);
//       

//       var Approver = '';
//       var user = await Api._getcurrentUser();
//       if (user) {
//         Approver = user.Title; //TODO:log(u)测试 用户名真正属性
//         
//       }
      
//       var para = {
//         Guid: changeApproveListGUID,    //变更审批记录表guid
//         Obj: {
//           Title: TaskItem.Title,
//           OData__x7533__x8bf7__x4eba_: TaskItem.OData__x7533__x8bf7__x4eba_, //申请人
//           OData__x7533__x8bf7__x4eba__x90e8__x95: updateItem_Item.OData__x7533__x8bf7__x4eba__x90e8__x95, //申请人部门
//           OData__x6587__x6863__x540d__x79f0_: updateItem_Item.OData__x6587__x6863__x540d__x79f0_, //文档名称                   
//           OData__x53d8__x66f4__x8bf4__x660e_: updateItem_Item.OData__x53d8__x66f4__x8bf4__x660e_, //变更说明
//           OData__x5ba1__x6279__x4eba_: Approver, //审批人
//           OData__x5ba1__x6279__x64cd__x4f5c_: status, //审批操作
//           OData__x5ba1__x6279__x610f__x89c1_: comments, //审批意见
//           OData__x6211__x7684__x4efb__x52a1_ID: taskId, //我的任务id
//           DocName: updateItem_Item.OData__x6587__x6863__x540d__x79f0_, //文档名称
//           DocVersionNumber: TaskItem.OData__x6587__x6863__x7248__x672c__x53, //版本号
//           CurrentApproverId: user.Id, // 审批人
//         }
//       };
      
//       
//       var result = await Api._saveaddDataGuid(para);
//     }
//   }

//   /**
//    * 废弃文档申请审批
//    * @param taskId 我的任务id
//    * @param status 审批操作
//    * @param comments 审批意见，退回或拒绝必填
//    */
//   public static async _abandonDocApproveItem(taskId: number, status: string = '同意', comments = ''){

    

//     var params = {
//       ListGUID: taskGuid,//我的任务guid
//       ItemId: taskId,
//     }
//     var TaskItem = await Api.GetListItemById(params);

//     if(TaskItem.ApprovalNode != '申请人修改'){
//       await Api._saveupdateDataByGuid({ListGUID: taskGuid, ItemId: taskId, Obj: {Status: 1}});

//       let Apply_Edit = {
//         Guid: MyApplyListGUID,   //我的申请guid
//         ItemId: TaskItem.MyApplyID,
//         Obj: {
//           "WFStatus": '流程执行中'
//         },
//       }
//       await Api._updateData(Apply_Edit);// 修改我的申请状态为 '流程执行中'
  
//       // 查询废弃文档申请item
//       var abandonItem_params = {
//         ListGUID: AbandonListGUID,//废弃文档申请guid
//         ItemId: TaskItem.NewDocApplyID,
//       }
//       var abandonItem_Item = await Api.GetListItemById(abandonItem_params);
//       
  
//       var Approver = '';
//       var user = await Api._getcurrentUser();
//       if (user) {
//         Approver = user.Title; //TODO:log(u)测试 用户名真正属性
//         
//       }
  
//       var data = {
//         Title: abandonItem_Item.Title,
//         OData__x7533__x8bf7__x4eba_: abandonItem_Item.OData__x7533__x8bf7__x4eba_, // 申请人
//         OData__x7533__x8bf7__x4eba__x90e8__x95: abandonItem_Item.OData__x7533__x8bf7__x4eba__x90e8__x95, // 申请人部门
//         OData__x7248__x672c__x53f7_: abandonItem_Item.OData__x7248__x672c__x53f7_, // 版本号
//         OData__x5e9f__x5f03__x8bf4__x660e_: abandonItem_Item.OData__x5e9f__x5f03__x8bf4__x660e_, // 废弃说明
//         OData__x5ba1__x6279__x4eba_: Approver, // 审批人
//         OData__x5ba1__x6279__x64cd__x4f5c_: status, // 审批操作
//         OData__x5ba1__x6279__x610f__x89c1_: comments, // 审批意见
//         MyTaskID: taskId, // 我的任务ID
//         DocVersionNumber: abandonItem_Item.OData__x7248__x672c__x53f7_, //版本号
//         CurrentApproverId: user.Id, // 审批人
//       };
  
//       
//       // return ;
  
//       var result = await Api.AddItemByListGUID({ ListGUID: AbandonApproveListGUID, Obj: data });
  
//       
//     }
//   }

// }
